import { appendO } from '$util';
import { writable, derived } from 'svelte/store';

export interface CustomerCaseStatDimension {
	name: string;
	estimatedValue: number;
}
export interface CustomerCaseLinkItem {
	href: string;
	title: string;
	summary: string;
	logo: string;
	pic: string;
	homePage: boolean;
	solutionPage: boolean;
	products: string[];
	industry: string;
	sortNo: number;
	stats?: CustomerCaseStatDimension[];
}

const _emptyCustomerCaseLinkItemAtHomePage: CustomerCaseLinkItem = {
	href: '#',
	title: '敬请期待',
	summary: '',
	logo: '',
	pic: '',
	homePage: true,
	solutionPage: true,
	products: ['group', 'mall'],
	industry: '',
	sortNo: 0
};

const _emptyCustomerCaseLinkItemAtSolutionPage: CustomerCaseLinkItem = {
	href: '#',
	title: '',
	summary: '',
	logo: '',
	pic: '',
	homePage: true,
	solutionPage: true,
	products: ['group', 'mall'],
	industry: '',
	sortNo: 0
};

const _emptyCustomerCaseLinkItemAtCustomerCasePage: CustomerCaseLinkItem = {
	href: '#',
	title: '7Cafe',
	summary: '助力组织升级, 实现商业数字化',
	logo: '',
	pic: '',
	homePage: true,
	solutionPage: true,
	products: ['group', 'mall'],
	industry: '零售',
	sortNo: 0
};

const _customerCaseItems: CustomerCaseLinkItem[] = [];

export const customerCaseItems = writable(_customerCaseItems);

export const showCustomerCaseLinksAtHomePage = derived(customerCaseItems, ($customerCaseItems) => {
	return appendO(
		$customerCaseItems.filter((i) => i.homePage),
		_emptyCustomerCaseLinkItemAtHomePage,
		24
	);
});

// export const showCustomerCaseLinksAtSolutionPage = derived(
// 	customerCaseItems,
// 	($customerCaseItems) => {
// 		return appendO(
// 			$customerCaseItems.filter((i) => i.solutionPage),
// 			_emptyCustomerCaseLinkItemAtSolutionPage,
// 			7
// 		);
// 	}
// );

export const buildCustomerCaseLinksAtSolutionPage = (product: string) =>
	derived(customerCaseItems, ($customerCaseItems) => {
		return appendO(
			$customerCaseItems.filter((i) => i.solutionPage && i.products.includes(product)),
			_emptyCustomerCaseLinkItemAtSolutionPage,
			7
		);
	});

export const showCustomerCaseLinksAtCustomerCasePage = derived(
	customerCaseItems,
	($customerCaseItems) => {
		return appendO($customerCaseItems, _emptyCustomerCaseLinkItemAtCustomerCasePage, 6);
	}
);
